home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / chisqr_cvf.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  72 lines

  1. ;$Id: chisqr_cvf.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1994-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;       CHISQR_CVF
  8. ;
  9. ; PURPOSE: 
  10. ;    This function computes the cutoff value (v) such that:
  11. ;                   Probability(X > v) = p
  12. ;       where X is a random variable from the Chi-square distribution
  13. ;       with (df) degrees of freedom. 
  14. ;
  15. ; CATEGORY:
  16. ;       Statistics.
  17. ; CALLING SEQUENCE:
  18. ;       Result = chisqr_cvf(P, DF)
  19. ;
  20. ; INPUTS:
  21. ;       P:    A non-negative scalar, in the interval [0.0, 1.0], of type
  22. ;             float or double that specifies the probability of occurance 
  23. ;             or success.
  24. ;
  25. ;      DF:    A positive scalar of type integer, float or double that 
  26. ;             specifies the degrees of freedom of the Chi-square distribution.
  27. ;
  28. ; EXAMPLE:
  29. ;       Compute the cutoff value (v) such that Probability(X > v) = 0.100
  30. ;       from the Chi-square distribution with (DF = 3) degrees of freedom. 
  31. ;       The result should be 6.25139
  32. ;         result = chisqr_cvf(0.100, 3) 
  33. ;
  34. ; REFERENCE:
  35. ;       ADVANCED ENGINEERING MATHEMATICS (seventh edition)
  36. ;       Erwin Kreyszig
  37. ;       ISBN 0-471-55380-8
  38. ;
  39. ; MODIFICATION HISTORY:
  40. ;       Modified by:  GGS, RSI, July 1994
  41. ;                     Minor changes to code. New documentation header.
  42. ;-
  43.  
  44. function chisqr_cvf, p, df
  45.  
  46.   on_error, 2  ;Return to caller if error occurs.
  47.  
  48.   if p lt 0. or p gt 1. then message, $
  49.     'p must be in the interval [0.0, 1.0]'
  50.   if p eq 0 then return, 1.0e12
  51.   if p eq 1 then return, 0.0
  52.   if df lt 0 then message, $
  53.     'Degrees of freedom must be positive.'
  54.  
  55.   case 1 of
  56.     df eq 1: up = 300.0 
  57.     df eq 2: up = 100.0 
  58.     df gt 2 and df le 5: up = 30.0
  59.     df gt 5 and df le 14: up = 20.0
  60.     else: up = 12.0
  61.   endcase
  62.   below = 0
  63.   while chisqr_pdf(up, df) lt (1 - p) do begin
  64.       below = up
  65.       up = 2 * up
  66.   endwhile
  67.  
  68.   return, bisect_pdf([1-p, df], 'chisqr_pdf', up, below)
  69. end
  70.  
  71.